package main

import (
	"context"
	demo "demo/kitex_gen/demo"
	"errors"
	"gitee.com/xvwen/goutils/pin"
)

// StudentServiceImpl implements the last service interface defined in the IDL.
type StudentServiceImpl struct{}

// AddStudent implements the StudentServiceImpl interface.
func (s *StudentServiceImpl) AddStudent(ctx context.Context, req *demo.Student) (resp *demo.Student, err error) {
	// TODO: Your code here...
	if req == nil {
		err = errors.New("参数不能为空！")
		return
	}
	if *req == (demo.Student{}) {
		err = errors.New("参数不能为空！")
	}
	resp = req
	return
}

// GetStudent implements the StudentServiceImpl interface.
func (s *StudentServiceImpl) GetStudent(ctx context.Context, req *demo.Student) (resp *demo.Student, err error) {
	// TODO: Your code here...
	if req == nil {
		err = errors.New("参数不能为空！")
		return
	}
	if req.GetPerson().GetName() == "张三" {
		resp = &demo.Student{
			Person: &demo.Person{
				Name:   pin.Str("李四"),
				Age:    pin.I32(16),
				Sex:    pin.Bool(true),
				Idcard: pin.Str("12345678901234567890"),
			},
			School: pin.Str("省重点希望中学"),
			Major:  pin.Str("普通高等教育"),
			Grade:  pin.Str("初一"),
			Phone:  pin.Str("13800000000"),
			Email:  pin.Str("13800000000@qq.com"),
		}
	} else {
		err = errors.New("未找到该学生！")
	}
	return
}

// UpdateStudent implements the StudentServiceImpl interface.
func (s *StudentServiceImpl) UpdateStudent(ctx context.Context, req *demo.Student) (resp *demo.Student, err error) {
	// TODO: Your code here...
	return
}

// DeleteStudent implements the StudentServiceImpl interface.
func (s *StudentServiceImpl) DeleteStudent(ctx context.Context, req *demo.Student) (resp *demo.Student, err error) {
	// TODO: Your code here...
	return
}
